<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="count++">{{ count }}</button>
        <!-- `greet` 是上面定义过的方法名 -->
        <button @click="greet">Greet</button>
    </div>
    <script type="module">
        import { createApp, ref } from 'https://lib.baomitu.com/vue/3.2.31/vue.esm-browser.js'
        createApp({
            setup() {
                const count = ref(0)

                const name = ref('vue.js')
                function greet(event) {
                    alert(`Hello ${name.value}!`)
                    if (event) {
                        alert(event.target.tagName)
                    }
                }
                return {
                    count,

                    name,
                    greet,
                }
            }
        }).mount('#app')
    </script>

    <div id="app2">
        <button @click="greet">button01 {{ count }}</button>
    </div>
    <script type="module">
        import { createApp, ref } from 'https://lib.baomitu.com/vue/3.2.31/vue.esm-browser.js'
        createApp({
            setup() {
                const count = ref(0)
                // button01 的点击时间, 如果方法名作为点击事件, 则会自动接收原生 DOM 事件并触发执行
                function greet(event) {
                    count.value++
                    console.log('click', event)
                }
                return {
                    count,
                    greet
                }
            }
        }).mount('#app2')
    </script>

<div id="app3">
    <button @click="greet('我是button02', $event)">button {{ count }}</button>
</div>
<script type="module">
    import { createApp, ref } from 'https://lib.baomitu.com/vue/3.2.31/vue.esm-browser.js'
    createApp({
        setup() {
            const count = ref(0)
            // button 的点击时间, 如果方法名作为点击事件, 则会自动接收原生 DOM 事件并触发执行
            function greet(params, event) {
                count.value++
                console.log('click', params, event)
            }
            return {
                count,
                greet
            }
        }
    }).mount('#app3')
</script>
</body>
</html>